Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ak-theme

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ak-theme

ak-theme webcomponent

  • 2.1.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

AtlasKit component registry Commitizen friendly semantic-release Report an issue Ask in our forum

Theme

The ak-theme component allows you to define theme variables for components that can affect how they look and feel.

Example theme

Try it out

Interact with a live demo of the ak-theme component.

Installation

npm install ak-theme

Using the component

HTML

The ak-theme package exports the Theme Skate component.

Import the component in your JS resource:

bundle.js
import 'ak-theme';

Now you can use the defined tag in your HTML markup:

index.html
<html>
<head>
  <script src="bundle.js"></script>
</head>
<body>
  <!-- ... -->
  <ak-theme></ak-theme>
</body>

or from within another JavaScript resource:

import Theme from 'ak-theme';

const component = new Theme();
document.body.appendChild(component);

React

This is a standard web component, if you want to use it in your React app, use the Skate.js React integration.

import Theme from 'ak-theme';
import reactify from 'skatejs-react-integration';

const ReactComponent = reactify(Theme, {});

ReactDOM.render(<ReactComponent />, container);

Theming components

Theming is a two-part process:

  1. Declaring a theme.

  2. Make a component themeable.

How to declare a theme

If you want to theme a component, declare a theme and specify some variables:

<ak-theme id="my-component">
  <ak-theme-var name="background" value="blue" />
  <ak-theme-var name="text" value="white" />
</ak-theme>

This example declares a theme for a component called my-component and exposes two variables:

  1. background
  2. text

How to make a themeable component

To make a component able to be themed, use the themeable() function that is exported from ak-theme.

import { define } from 'skatejs';
import { themeable } from 'ak-theme';

export default define('my-component', themeable({
  render(elem) {
    return (
      <style>
        background-color: {elem.themeVars.background}
      </style>
    );
  }
}));

The function themeable() does several things for you:

  1. themeVars are always populated with the corresponding theme's variables.
  2. themeVars is updated if the theme is updated.
  3. themeVars is updated if the component's theme is changed.

When using themeable() you only have to worry about rendering your component based on some theme variables.

How to set a component's theme

A themeable component's theme is a theme that has an id that matches its tag name. However, if you need to change the theme a component should have, you can set its themeName property. This property is also reflected, so you can use the theme-name attribute just the same.

This is handy when the display of a particular component may changes depending on the parent's context.

<ak-button>My button</ak-button>
<ak-navigation>
  <ak-button theme-name="nav-button">Navigation button</ak-button>
</ak-navigatoin>

Members

themeName : string

The id of the theme the component should use. This defaults to the tag name of the component.

themeProps : string

The deserialised variables from the component's current theme. These are automatically kept in sync.

themeName : string

The id of the theme the component should use. This defaults to the tag name of the component.

Kind: global variable

themeProps : string

The deserialised variables from the component's current theme. These are automatically kept in sync.

Kind: global variable

Support and feedback

We're here to help!

Let us know what you think of our components and docs, your feedback is really important for us.

Community support

Ask a question in our forum.

Check if someone has already asked the same question before.

Create a support ticket

Are you in trouble? Let us know!

Keywords

FAQs

Package last updated on 03 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc